<?php

class Application_Model_DbTable_Basicinfo extends Zend_Db_Table_Abstract
{

    protected $_name = 'BasicInfo';
    protected $_primary = 'id';

    public function getBasicInfo($userID)
    {
    	$userID = (int)$userID;
    	$row = $this->fetchRow("User_id = " . $userID);
    	if (!$row) {
			return null;
		}
    	return $row->toArray();
    }
    
    public function existsBasicInfo($userID)
    {
    	$userID = (int)$userID;
    	$row = $this->fetchRow("User_id = " . $userID);
    	
    	if(!$row)
    	{
    		return '0';
    	}
    	else return '1';
    }
    
    public function createBasicInfo($userID, $visible)
    {
    	$data = array(
    		'FirstName' => "",
    		'LastName' => "",
    		'Gender' => 0,		// 1 = Male, 2 = Female.
    		'Birthday' => "01-01-1900",
    		'Education' => "",
    		'About' => "",
    		'Country' => "",
    		'City' => "",
    		'ViewPermitions' => $visible,
    		'User_id' => $userID,
    	);
    	$this->insert($data);
    }

    public function editBasicInfo($basicInfoId, $first, $last, $sex, $birthday, $edu, $about, $country, $city, $visible)
    {
    	$data = array(
    		'FirstName' => $first,
    		'LastName' => $last,
    		'Gender' => $sex,
    		'Birthday' => $birthday,
    		'Education' => $edu,
    		'About' => $about,
    		'Country' => $country,
    		'City' => $city,
    		'ViewPermitions' => $visible,
    	);
    	$this->update($data, 'id = '. (int)$basicInfoId);
    }
}

